import axios from 'axios'
import * as constants from './constants'

const changeLogin = () => ({
  type: constants.CHANGE_LOGIN,
  value: true
})

export const login = (user, pwd) => {
  return (dispatch) => {
    axios.get(`/api/login.json?account=${user}&password=${pwd}`).then(({ data: { data } }) => {
      if (data) {
        dispatch(changeLogin())
      } else {
        alert('登录失败')
      }
    })
  }
}

export const logout = () => ({
  type: constants.CHANGE_LOGOUT,
  value: false
})